
AddCSLuaFile( "shared.lua" )

SWEP.Author			= ""
SWEP.Contact		= ""
SWEP.Purpose		= ""
SWEP.Instructions	= ""

if ( CLIENT ) then

SWEP.PrintName			= "Speed Booster"		// 'Nice' Weapon name (Shown on HUD)	
SWEP.Slot				= 0						// Slot in the weapon selection menu
SWEP.SlotPos			= 10					// Position in the slot
SWEP.DrawAmmo			= false					// Should draw the default HL2 ammo counter
SWEP.DrawCrosshair		= true 					// Should draw the default crosshair
SWEP.DrawWeaponInfoBox	= false					// Should draw the weapon info box
SWEP.BounceWeaponIcon   = false					// Should the weapon icon bounce?
SWEP.SwayScale			= 1.0					// The scale of the viewmodel sway
SWEP.BobScale			= 1.0					// The scale of the viewmodel bob
SWEP.WepSelectIcon		= surface.GetTextureID( "weapons/swep" )

end

SWEP.ViewModelFOV	= 62
SWEP.ViewModelFlip	= false
SWEP.ViewModel		= "models/weapons/v_357.mdl"
SWEP.WorldModel		= "models/weapons/w_357.mdl"
SWEP.AnimPrefix		= "python"
SWEP.DrawAmmo	= true;

SWEP.Spawnable			= false
SWEP.AdminSpawnable		= false

SWEP.Primary.ClipSize		= 100				// Size of a clip
SWEP.Primary.DefaultClip	= 100				// Default number of bullets in a clip
SWEP.Primary.Automatic		= false				// Automatic/Semi Auto
SWEP.Primary.Ammo			= "fatigue"

SWEP.Secondary.ClipSize		= -1					// Size of a clip
SWEP.Secondary.DefaultClip	= -1				// Default number of bullets in a clip
SWEP.Secondary.Automatic	= false				// Automatic/Semi Auto
SWEP.Secondary.Ammo			= "none"

SWEP.NextFire = 0
SWEP.BoostText = ""
SWEP.Fatigue = 90
SWEP.NextFatHeal = 0
SWEP.RenewFat = 1
SWEP.StyleSpeed = 0.1
SWEP.SecondaryHit = false

/*---------------------------------------------------------
   Name: SWEP:PrimaryAttack( )
   Desc: +attack1 has been pressed
---------------------------------------------------------*/
function SWEP:PrimaryAttack()
	
		if self:CanTakeFatigue(self.Fatigue) then
	
			GAMEMODE:SetPlayerSpeed( self.Owner, 1500, 2000 )
			
			self.NextFire = CurTime() + 8
			
			self:TakeFatigue( self.Fatigue )
			
			timer.Simple(5, function() GAMEMODE:SetPlayerSpeed( self.Owner, 400, 600 ) end)
			
			self:CreateEffect( "cball_explode" )
			if CLIENT then self.Owner:InSpeed() end
			
		end
		
end

function SWEP:CreateEffect( eff )

	local pos = self.Owner:GetPos()
	
	local effect = EffectData()
	
		effect:SetStart(pos)
		effect:SetOrigin(pos)
		effect:SetScale( 1 )
	
	util.Effect( eff, effect )
	
end


/*---------------------------------------------------------
   Name: SWEP:SecondaryAttack( )
   Desc: +attack2 has been pressed
---------------------------------------------------------*/
function SWEP:SecondaryAttack()
	
		if self.SecondaryHit then return end
	
			self.SecondaryHit = true
			
			self.Owner:SetGroundEntity( NULL )
			--self.Owner:SetVelocity( self.Owner:GetVelocity() * -1 + self.Owner:GetAimVector() * 1000 )
			self.Owner:SetVelocity(self.Owner:GetVelocity() * 2)
			
			self:SetNextSecondaryFire( CurTime() + 1 )
			
			self.NextFire = CurTime() + 1
			
			self:TakeFatigue( self.Fatigue )
			
			self:CreateEffect( "Explosion" )
	
end

/*---------------------------------------------------------
   Name: SWEP:ShootBullet( )
   Desc: A convenience function to shoot bullets
---------------------------------------------------------*/
function SWEP:ShootEffects()

	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) 		// View model animation
	self.Owner:MuzzleFlash()								// Crappy muzzle light
	self.Owner:SetAnimation( PLAYER_ATTACK1 )				// 3rd Person Animation

end


/*---------------------------------------------------------
   Name: SWEP:ShootBullet( )
   Desc: A convenience function to shoot bullets
---------------------------------------------------------*/
function SWEP:ShootBullet( damage, num_bullets, aimcone )
	
	--
	
end

function SWEP:CanBoost()

	if CurTime() > self.NextFire then 
	
		return true
		
	else
	
		return false
		
	end
	
end

col = Color( 255, 255, 255, 255 )

function SWEP:DrawHUD()

	local w = ScrW()
	local h = ScrH()
	
	if self:CanTakeFatigue(self.Fatigue) then
	
		self.BoostText = "Boost is ready!"
		
	else
	
		self.BoostText = "Boost is not ready!"
		
	end
	
		draw.DrawText( self.BoostText, "Trebuchet22", w / 2, h / 2, col, 1)
		
	
end

function SWEP:TakeFatigue( ammount )
	
	if CLIENT then return end
	
	self.Weapon:SetClip1( self.Weapon:Clip1() - ammount )
	
	self.NextFatHeal = CurTime() + self.RenewFat
	
end

function SWEP:CanTakeFatigue( ammount )

	if self.Weapon:Clip1() - ammount <= 0 then
		return false
	else
		return true
	end
	
end

function SWEP:Think()

if CLIENT then return end
	
	if CurTime() > self.NextFatHeal and self.Weapon:Clip1() < 100 and CurTime() > self.StyleSpeed then
		
		self.NextFatHeal = CurTime() + 0.1
		self.Weapon:SetClip1( self.Weapon:Clip1() + 1 )
		
	end
	
	if self.Owner:OnGround() and self.SecondaryHit then
		self.SecondaryHit = false
	end

end
